package cloud.demarcia.crawler3.utils;

public class StringUtils  {


    public int extractIdFromLink(String picLink){
        int length=picLink.length();
        String x = picLink.substring(length - 7, length - 4);
        return Integer.parseInt(x);
    }


    public String urlLegalize(String urlString) {
        if (!urlString.startsWith("http")) {
            while(urlString.length()>0&&urlString.charAt(0)=='/'){
                urlString=urlString.substring(1);
            }
            urlString = "http://" + urlString;
        }
        return urlString;
    }

    public int BearIdOnSite4InfoPage(String link) {
        link = link.substring(link.length() - 25);
        String s = link.split("/")[1];
        return Integer.parseInt(s);
    }

    public String processLink4InfoPage(String rawLink) {
        int index1 = rawLink.indexOf('(');
        int index2 = rawLink.indexOf(')');
        return "http:" + rawLink.substring(index1 + 1, index2);

    }

    public String fileNameLegalize(String fileName, String urlString) {
        if (fileName.length() == 0) {
            return urlString.length() > 7 ? urlString.substring(urlString.length() - 7) : urlString;
        } else {
            return fileName;
        }
    }


    public int extractSortFromDetailPage(String attrString){
        char c=attrString.charAt(attrString.length()-1);
        return Integer.parseInt(c+"");
    }

}
